package hd.util.load;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

/**
 * 子线程加载并异步返回
 * <p/>
 * Created by haidy on 14/12/4.
 */
public class BaseLoader {
    public static void start(final OnLoaderListener listener) {
        new Thread() {
            @Override
            public void run() {
                listener.load();
                new Handler(Looper.getMainLooper()) {
                    @Override
                    public void handleMessage(Message msg) {
                        listener.finish();
                    }
                }.sendEmptyMessage(0);
            }
        }.start();
    }

    public interface OnLoaderListener {
        void load();

        void finish();
    }
}
